package com.module.TraceSource.manager;

import java.util.List;

import org.hibernate.Session;

import base.dao.GenericHibernateDao;
import base.manager.GenericHibernateManager;

import com.module.TraceSource.dao.TsEntEventDao;
import com.module.TraceSource.vo.TsEntEvent;

public class TsEntEventManager extends GenericHibernateManager<TsEntEvent,Long>{
	private TsEntEventDao dao = TsEntEventDao.getInstance();
	private static TsEntEventManager service;
	private TsEntEventManager(){
		super();
	}

	public synchronized static TsEntEventManager getInstance(){
		if(service == null){
			service = new TsEntEventManager();
		}
		return service;
	}

	@Override
	public GenericHibernateDao<TsEntEvent, Long> getDao() {
		return dao;
	}
	
	/**
	 *  根据流程获取事件
	 * @param flowId
	 * @return
	 * @throws Exception
	 */
	public List findEntEventByFlowId(String flowId) throws Exception{
		Session session = this.getSession();
		List<TsEntEvent> list = null;
		try{
			list = dao.findEntEventByFlowId(session, flowId);
			this.closeSession();
		}catch(Exception e){
			this.closeSession();
		}
		return list;
	}
	
	public TsEntEvent getEventById(int eventId){
		Session session = this.getSession();
		TsEntEvent vo = null;
		try{
			vo = (TsEntEvent) dao.findUniqueObjectBySQL(session, "from TsEntEvent where id="+eventId);
		}catch(Exception e){
			this.closeSession();
		}
		return vo;
	}
}
